#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setEchoMode(QLineEdit::Password);

}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString text1 = ui->lineEdit->text();
    QString text2 = ui->lineEdit_2->text();

    if(text1.isEmpty() || text2.isEmpty())
    {
        ui->label_3->setText("密码为空");
    }
    else if(text1 == text2)
    {
        ui->label_3->setText("两次密码输入正确");
    }
    else
    {
        ui->label_3->setText("两次密码输入不正确");
    }

     timer = new QTimer(this);
     connect(timer, &QTimer::timeout, this, &Widget::func);
     timer->start(2000);
}

void Widget::on_checkBox_toggled(bool checked)
{
    if(checked)
        ui->lineEdit->setEchoMode(QLineEdit::Normal);
    else
        ui->lineEdit->setEchoMode(QLineEdit::Password);
}

void Widget::on_checkBox_2_toggled(bool checked)
{
    if(checked)
        ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
    else
        ui->lineEdit_2->setEchoMode(QLineEdit::Password);
}

void Widget::func()
{
    if(ui->checkBox->isChecked())
    {
            ui->lineEdit->setEchoMode(QLineEdit::Password);
            ui->lineEdit_2->setEchoMode(QLineEdit::Password);
            timer->stop();
    }
    if(ui->checkBox_2->checkState())
    {
            ui->lineEdit->setEchoMode(QLineEdit::Password);
            ui->lineEdit_2->setEchoMode(QLineEdit::Password);
            timer->stop();
    }
}
